import "@site/src/languages/highlight";

# RenderTarget

**Description:**

&emsp;&emsp;A RenderTarget is a buffer that allows you to render a Node into a texture.

**Class Object:** [RenderTarget Class](/docs/api/Class%20Object/RenderTarget).

**Inherits from:** [Object](/docs/api/Class/Object).

## width

**Type:** Readonly Field.

**Description:**

&emsp;&emsp;The width of the rendering target.

**Signature:**
```tl
const width: integer
```

## height

**Type:** Readonly Field.

**Description:**

&emsp;&emsp;The height of the rendering target.

**Signature:**
```tl
const height: integer
```

## texture

**Type:** Readonly Field.

**Description:**

&emsp;&emsp;The texture generated by the rendering target.

**Signature:**
```tl
const texture: Texture2D
```

## camera

**Type:** Field.

**Description:**

&emsp;&emsp;The camera used for rendering the scene.

**Signature:**
```tl
camera: Camera
```

## render

**Type:** Function.

**Description:**

&emsp;&emsp;Renders a node to the target without replacing its previous contents.

**Signature:**
```tl
render: function(self: RenderTarget, target: Node)
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| target | Node | The node to be rendered onto the render target. |

## renderWithClear

**Type:** Function.

**Description:**

&emsp;&emsp;Clears the previous color, depth and stencil values on the render target.

**Signature:**
```tl
renderWithClear: function(
		self: RenderTarget,
		color: Color,
		depth?: number --[[1]],
		stencil?: number --[[0]]
	)
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| color | Color | The clear color used to clear the render target. |
| depth | number | [optional] The value used to clear the depth buffer of the render target. Default is 1. |
| stencil | number | [optional] The value used to clear the stencil buffer of the render target. Default is 0. |

## renderWithClear

**Type:** Function.

**Description:**

&emsp;&emsp;Renders a node to the target after clearing the previous color, depth and stencil values on it.

**Signature:**
```tl
renderWithClear: function(
		self: RenderTarget,
		target: Node,
		color: Color,
		depth?: number --[[1]],
		stencil?: integer --[[0]]
	)
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| target | Node | The node to be rendered onto the render target. |
| color | Color | The clear color used to clear the render target. |
| depth | number | [optional] The value used to clear the depth buffer of the render target. Default is 1. |
| stencil | number | [optional] The value used to clear the stencil buffer of the render target. Default is 0. |

## saveAsync

**Type:** Function.

**Description:**

&emsp;&emsp;Saves the contents of the render target to a PNG file asynchronously.

**Signature:**
```tl
saveAsync: function(self: RenderTarget, filename: string)
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| filename | string | The name of the file to save the contents to. |